package com.hc.conferencecheck.service.impl;

import com.hc.conferencecheck.entity.QrCode;
import com.hc.conferencecheck.entity.QrCodeExample;
import com.hc.conferencecheck.mapper.QrCodeMapper;
import com.hc.conferencecheck.service.QrCodeService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 二维码图片service实现类
 */
@Service
public class QrCodeServiceImpl implements QrCodeService {
    @Resource
    private QrCodeMapper qrCodeMapper;

    /**
     * 根据type和identifi_id获取QrCode对象
     */
    public int deleteQrCodeByTypeAndIdentifierId(int type, int identifyId) {
        QrCodeExample example = new QrCodeExample();
        QrCodeExample.Criteria criteria = example.createCriteria();
        criteria.andTypeEqualTo(type);
        criteria.andIdentifyIdEqualTo(identifyId);

        int i = qrCodeMapper.deleteByExample(example);
        return i;
    }

    /**
     * 根据type和identifi_id获取QrCode对象
     */
    public QrCode selectQrCodeByTypeAndIdentifierId(int type, int identifyId) {
        QrCodeExample example = new QrCodeExample();
        QrCodeExample.Criteria criteria = example.createCriteria();
        criteria.andTypeEqualTo(type);
        criteria.andIdentifyIdEqualTo(identifyId);

        List<QrCode> qrCodes = qrCodeMapper.selectByExample(example);
        if (qrCodes != null && qrCodes.size() > 0) {
            return qrCodes.get(0);
        }
        return null;
    }
}
